package com.wmx.jdk8;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * IntStream 流
 *
 * @author wangMaoXiong
 * @version 1.0
 * @date 2022/6/22 19:38
 */
public class IntStreamTest {

    /**
     * IntStream mapToInt(ToIntFunction<? super T> mapper)：Stream 转 IntStream
     * Stream<Integer> boxed()：对原生装箱，即将基本类型转为包装类型
     */
    @Test
    public void testMapToInt() {
        List<Integer> list = new ArrayList<>();
        for (int i = 0, max = 10; i < max; i++) {
            list.add(i);
        }
        // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        System.out.println(list);
        List<Integer> collect = list.stream().mapToInt(item -> item).map(item -> ++item).boxed().collect(Collectors.toList());
        // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        System.out.println(collect);
    }

}
